﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CreateStaticHtml.Models;
using CreateStaticHtml.Interface;

namespace CreateStaticHtml.Impl
{
    public class ImplProduct : IProduct
    {
        private DavidDB.ADO.DBManager dbmanager = null;


        #region 返回接口实现

        private ImplProduct(DavidDB.ADO.DBManager db) { this.dbmanager = db; }

        public static IProduct GetInstance(DavidDB.ADO.DBManager db)
        {
            IProduct instance = new ImplProduct(db);
            return instance;
        }
        #endregion
        #region 默认接口实现

        /// <summary>
        /// 得到所有 产品在大项目中尽量少用，这个方法返回的数据量过于庞大
        /// </summary>
        /// <returns>所有产品</returns>
        public List<Product> GetList()
        {
            Product field = new Product();
            var objs = dbmanager.GetList(field);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 分页显示产品
        /// </summary>
        /// <param name="PageSize">每页记录数</param>
        /// <param name="NowPage">当前页</param>
        /// <param name="PageCount">总共多少页</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns>查询到的记录</returns>
        public List<Product> GetListByPage(int PageSize, int NowPage, out int PageCount, out int recordCount)
        {
            Product field = new Product();
            var objs = dbmanager.GetListByPage(PageSize, NowPage, out PageCount, out recordCount, field);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 分页模糊查询产品
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <param name="PageSize">每页记录数</param>
        /// <param name="NowPage">当前页</param>
        /// <param name="PageCount">总共多少页</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns>查询到的记录</returns>
        public List<Product> GetListByPageLikeKey(Product product, int PageSize, int NowPage, out int PageCount, out int recordCount)
        {
            var objs = dbmanager.GetListByPageLikeKey(PageSize, NowPage, product, out PageCount, out recordCount);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 分页查询产品
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <param name="PageSize">每页记录数</param>
        /// <param name="NowPage">当前页</param>
        /// <param name="PageCount">总共多少页</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns>查询到的记录</returns>
        public List<Product> GetListByPageAndKeys(Product product, int PageSize, int NowPage, out int PageCount, out int recordCount)
        {
            var objs = dbmanager.GetListByPageAndKeys(PageSize, NowPage, product, out PageCount, out recordCount);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 得到一个产品
        /// </summary>
        /// <param name="id">对象实体</param>
        /// <returns>对象</returns>
        public Product GetModel(int id)
        {
            Product field = new Product();
            field.Id = id;
            return dbmanager.GetModel(field) as Product;
        }

        /// <summary>
        /// 保存一个产品
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <returns>编号</returns>
        public int Insert(Product product)
        {
            return dbmanager.Insert(product);
        }

        /// <summary>
        /// 按关键字查询头几条
        /// </summary>
        /// <param name="count">数量</param>
        /// <returns>产品的列表</returns>
        public List<Product> GetTopList(int count)
        {
            Product field = new Product();
            var objs = dbmanager.GetTopList(count, field);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 判断产品是否唯一存在
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <returns>是否存在</returns>
        public bool IsExist(Product product)
        {
            return dbmanager.IsExist(product);
        }

        /// <summary>
        /// 判断产品是否存在
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <returns>是否存在</returns>
        public bool IsJustExist(Product product)
        {
            return dbmanager.IsJustExist(product);
        }

        /// <summary>
        /// 得到关键字等于。。。的所有产品
        /// </summary>
        /// <param name="product">对象实体</param>
        /// <returns>产品的List</returns>
        public List<Product> GetSomeObject(Product product)
        {
            var objs = dbmanager.GetSomeObject(product);
            List<Product> fields = new List<Product>();
            foreach (Product _field in objs)
            {
                fields.Add(_field);
            }
            return fields;
        }

        /// <summary>
        /// 编辑一个产品
        /// </summary>
        /// <param name="obj">对象实体</param>
        public void Edit(Product product)
        {
            dbmanager.Edit(product);
        }

        /// <summary>
        /// 删除一个产品
        /// </summary>
        /// <param name="product">对象实体</param>
        public void Delete(Product product)
        {
            dbmanager.Delete(product);
        }

        /// <summary>
        /// 删除所有产品
        /// </summary>
        public void DeleteAll()
        {
            Product field = new Product();
            dbmanager.DeleteAll(field);
        }

        /// <summary>
        /// 按关键字删除
        /// </summary>
        /// <param name="product">对象实体</param>
        public void DeleteColumByKey_Value(Product product)
        {
            dbmanager.DeleteColumByKey_Value(product);
        }

        #endregion

        #region 自定义接口实现


        #endregion

    }
}
